-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUGFIX canary] Meta refactor #11966
Conversation
Meta.prototype['writable' + capitalized] = function(create) { | ||
let ret = this[key]; | ||
if (!ret) { | ||
ret = this[key] = create(this.source); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we can do this in a quicker way, as long as we are aware which are for instances and which are for classes.
basically, for an instance if we could do
ret = this[key] = new InheritedObjectSubclass();
for classes we would do something like:
function InheritedObjectSubclass() {
}
InheritedObjectSubclass.prototype = create(this.source);
we would still have 1 shape per InheritedObjectSubclass (which still will likely cause grief), but we could fast-path the instantiation for instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Right now there is a single shape at every level, but you're saying it may be worth it to accept a shape-per-class in order to make instance creation faster, since presumably there are so many more instances than classes.
I guess we would need to try and measure the impact, I am uncertain. Deoptimizing some key method due to multiple-shapeness could be way worth than the instance instantiation cost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but you're saying it may be worth it to accept a shape-per-class in order to make instance creation faster
You know, if we do the readable/writable thing correctly, the above likely doesn't matter. As we will now only lazily create the children. In all common cases, I hope that means that we just wont incur the cost of the children at all.
We may want to add logging to detect when this assumption is violated.
We can keep it up our sleeves, but after reading the full PR, I believe wont provide any value.
I think we should merge this, so further work can be based off it. I would also like to get perf feedback from apps on canary, to confirm that we are at least not making anything worse by accident. |
Restarted sauce labs job. |
I'm 👍 on landing this in canary. |
Let me get some time this afternoon to run this in some apps, just want to do our due diligence. |
} | ||
}); | ||
|
||
function EmptyObject() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slightly more concise version is possible
export default function EmptyObject() {
}
EmptyObject.prototype = null
6ms -> noise turns out there is no 0 cost abstraction in JS yet...
something of interest, i have added some ghetto instrumentation to get a picture of how the new code is being utilized:
the following is likely the worse offender in-terms of performance.
it appears the most costly, are listeners to descriptors that likely never change (at least not in this example). In addition, these listeners could actually be inherited listeners, as the CP in question are defined on the classes, not the instances. It seems like an interesting optimization to pursue at a future point in time. |
In one example this removes nearly 8% of gets
speed up Meta instantiation
[BUGFIX canary] Meta refactor
this is a great start in cleaning up our internals. Good job @ef4, this will be nice to work on-top of for our next opts. |
} | ||
}); | ||
|
||
QUnit.test('meta is not enumerable', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just reading through this PR out of curiosity. There may be a reason I don't understand, but this test seem to be repeated twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, seems like a dupe. Mind submitting a PR to remove the duplicate?
This refactors the meta object as a step toward optimizing it better.